/**
 * @Project Name:blog-business-service
 * @Package Name:cn.hoofungson.blog.business.service.provider.convert.loginLog
 * @Since JDK 1.8
 */

package cn.hoofungson.blog.business.service.provider.converter.user;

import cn.hoofungson.blog.business.service.interfaces.domain.dto.user.LoginLogDTO;
import cn.hoofungson.blog.business.service.interfaces.domain.dto.user.UserDTO;
import cn.hoofungson.blog.business.service.provider.model.entity.user.LoginLogPO;
import cn.hoofungson.blog.business.service.provider.model.entity.user.UserPO;
import org.springframework.cglib.beans.BeanCopier;

/**
 * @Description: LoginLogConverter
 * @Author 胡松 hoofungson@163.com
 * @Date 2020-03-25 8:35
 * @Version V1.0
 */
public class LoginLogConverter {

    /**
     * DTO转PO
     *
     * @param loginLogDTO
     * @param loginLogPO
     **/
    public static void convert(LoginLogDTO loginLogDTO, LoginLogPO loginLogPO) {
        if (null == loginLogDTO) {
            return;
        }
        if (null == loginLogPO) {
            return;
        }
        BeanCopier.create(loginLogDTO.getClass(), loginLogPO.getClass(), false)
                .copy(loginLogDTO, loginLogPO, null);
        if (null == loginLogDTO.getUserDTO()) {
            return;
        }
        UserDTO userDTO = loginLogDTO.getUserDTO();
        UserPO userPO = new UserPO();
        BeanCopier.create(userDTO.getClass(), userPO.getClass(), false)
                .copy(userDTO, userPO, null);
        loginLogDTO.setUserDTO(userDTO);
    }

    /**
     * PO转DTO
     *
     * @param loginLogPO
     * @param loginLogDTO
     **/
    public static void convert(LoginLogPO loginLogPO, LoginLogDTO loginLogDTO) {
        if (null == loginLogPO) {
            return;
        }
        if (null == loginLogDTO) {
            return;
        }
        BeanCopier.create(loginLogPO.getClass(), loginLogDTO.getClass(), false)
                .copy(loginLogPO, loginLogDTO, null);
        if (null == loginLogPO.getUserPO()) {
            return;
        }
        UserPO userPO = loginLogPO.getUserPO();
        UserDTO userDTO = new UserDTO();
        BeanCopier.create(userPO.getClass(), userDTO.getClass(), false)
                .copy(userPO, userDTO, null);
        loginLogPO.setUserPO(userPO);
    }
}
